<#include "../../select.ftl" />
<#assign security=JspTaglibs["/WEB-INF/security.tld"] />
<!DOCTYPE html>
<html>
<head>
    <title>维护页面</title>
    <script type="text/javascript">
        $(function () {
            $("#importCustBtn").click(function () {
                $("#custUploadForm input[type=file]").click();
            });

            $("#custUploadForm input[name=file]").live("change", function () {
                $("#custUploadForm").ajaxSubmit({
                    success: function (data) {
                        importCustSuccess(data);
                    }
                });
            });
        });
        function importCustSuccess(data) {
            var result = JSON.parse(data);
            if (result.returnCode == 1) {
                var url = "${absoluteContextPath}/members/customer/importCust";
                var path = result.content;
                $.ajax({
                    url: url,
                    type: 'post',
                    data: {path: path},
                    success: function (msg) {
                        refreshTable();
                        msg = JSON.parse(msg);
                        var pop_div = $('#errorMessage');
                        var message = "";
                        var texts = {};
                        texts = msg.returnMsg.split("!");
                        for (var r = 0; r < texts.length; r++) {
                            if (r < texts.length - 1) {
                                message += (texts[r] + "!<br>");
                            } else {
                                message += (texts[r]);
                            }
                        }
                        $("#info").html(message);
                        pop_div.modal('show');
                        $("input[name=file]").val(null);

                    }
                });
            } else {
                $.showMessage({parentId: "showMessage", message: "<strong>错误信息</strong>：" + result.returnMsg, type: "error"});
            }
        }

        function popAddOrModify(id) {
            var data = {};
            var url = '${absoluteContextPath}/members/customer';
            if (id != undefined) {
                data.id = id;
                url = url + "/goEdit";
            } else {
                url = url + "/goAdd";
            }
            $.ajax({
                url: url,
                type: 'post',
                data: data,
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        var pop_div = $('#myModal');
                        pop_div.html(data.content.data);
                        pop_div.modal('show');
                    } else {
                        $.showMessage({parentId: "showMessage", message: "数据加载异常！", type: "success"});
                    }
                }
            });
        }

        function deleteCustomer() {
            var i = 0;
            $("input[name=ids]").each(function () {
                if ($(this).prop("checked")) {
                    i++;
                }
            });
            if (i == 0) {
                $.showMessage({parentId: "showMessage", message: "请选择您要删除的记录！", type: "success"});
                return false;
            } else {
                $.confirm({
                    confirm: function () {
                        var values = "";
                        $("input[name=ids]").each(function () {
                            if ($(this).prop("checked")) {
                                values += $(this).val() + ",";
                            }
                        });
                        $("#confirmModal").modal("hide");
                        $.post("${absoluteContextPath}/members/customer/delete", {
                            'ids': values
                        }, function (data) {
                            data = JSON.parse(data);
                            if (data.returnCode == 1) {
                                $.showMessage({parentId: "showMessage", message: "数据删除成功！", type: "success"});
                                refreshTable();
                            } else {
                                $.showMessage({parentId: "showMessage", message: "数据删除异常！", type: "error"});
                            }
                        });
                    }
                });
            }
        }

        //导出
        function popExportExcel() {
            $("#search_customer_table").attr('action', '${absoluteContextPath}/members/customer/export');
            $("#search_customer_table").submit();
        }
        function doDownLoadTemplate() {
            $("#Form_Download").submit();
        }
        function refreshTable() {
            $("input[name=currentPage]").val(1);
            $("#search_customer_table").ajaxSubmit({
                url: '${absoluteContextPath}/members/customer/ajaxList',
                success: function (data) {
                    var data = JSON.parse(data);
                    if (data.returnCode == 1) {
                        $("#tableContent").html(data.content.data);
                    } else {
                        $.showMessage({parentId: "showMessage", message: "表格数据加载异常！", type: "success"});
                    }
                }
            });
        }

        var fn = function () {
            $("#search_customer_table").submit();
        }

        setInterval(fn, 216000000);

    </script>
</head>
<body>

<div class="breadcrumbs">
    <ol class="breadcrumb">
        <li><a href="${absoluteContextPath}/home"><i class="fa fa-home"></i>首页</a></li>
        <li><a href="#">会员管理</a></li>
        <li class="active">客户信息</li>
    </ol>
</div>

<div class="main">
    <!-- row -->
    <div class="row">
        <div class="col-md-12">
            <section class="tile">
                <!-- tile body -->
                <div class="tile-body">
                    <div id="showMessage"><#include "../../message.ftl" /></div>
                    <div class="form-horizontal">
                        <form id="search_customer_table" action="${absoluteContextPath}/members/customer/list"
                              method="post">
                            <input type="hidden" name="pageSize" value="${customersTable.page.pageSize}"/>
                            <input type="hidden" name="currentPage" value="${customersTable.page.currentPage}"/>


                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">卡号</label>

                                    <div class="col-sm-8">
                                        <input class="form-control" name="cardId" value="${customerParams.cardId!''}"
                                               placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">客户姓名</label>

                                    <div class="col-sm-8">
                                        <input class="form-control" name="customerName"
                                               value="${customerParams.customerName!''}" placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">年龄</label>

                                    <div class="col-sm-8">
                                        <input class="form-control" name="age" value="${customerParams.age!''}"
                                               placeholder="" type="text">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">性别</label>

                                    <div class="col-sm-8">
                                    <@select name="sex" value="${customerParams.sex!''}" list=sexTypeList class="form-control"/>
                                        <#--<input class="form-control" name="sex" value="${customerParams.sex!''}" placeholder="" type="text">-->
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">电话</label>

                                    <div class="col-sm-8">
                                        <input class="form-control" name="phone" value="${customerParams.phone!''}"
                                               placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">身份证</label>

                                    <div class="col-sm-8">
                                        <input class="form-control" name="staffId" value="${customerParams.staffId!''}"
                                               placeholder="" type="text">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4 control-label" for="exampleInputEmail2">地址</label>

                                    <div class="col-sm-8">
                                        <input class="form-control" name="address" value="${customerParams.address!''}"
                                               placeholder="" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-md-4">
                                    <label class="col-sm-4"></label>

                                    <div class="col-sm-8">
                                        <button type="button" class="btn btn-primary" onclick="refreshTable()">查询
                                        </button>
                                        <button type="reset" class="btn btn-default">重置</button>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </section>
            <section class="tile">
                <div class="tile-header">
                    <h1>
                        <button type="button" class="btn btn-green" onclick="popAddOrModify();"><i
                                class="fa fa-plus"></i><span class="margin-left-5">新增</span></button>
                        <button type="button" class="btn btn-cyan" onclick="deleteCustomer();"><i
                                class="fa fa-trash-o"></i><span class="margin-left-5">删除</span></button>
                        <button type="button" class="btn btn-green" onclick="popExportExcel();"><i
                                class="fa fa-plus"></i><span class="margin-left-5">导出</span></button>

                        <button id="importCustBtn" type="button" class="btn btn-cyan"><i
                                class="fa fa-arrow-circle-o-down"></i><span class="margin-left-5">导入模板</span>
                        </button>


                        <button type="button" class="btn  btn-primary" onclick="doDownLoadTemplate();"><i
                                class="fa fa-download"></i><span class="margin-left-5">导入模板下载</span></button>

                    </h1>
                </div>
                <div class="tile-body nopadding">
                    <div class="table-responsive" id="tableContent">
                    <#include "table.ftl"/>
                    </div>
                </div>
            </section>
        </div>
    </div>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    </div>
    <form id="Form_Download" action="${absoluteContextPath}/members/customer/downloadTemplate" method="post"
          style="display: none">
        <input name="serverFileName" type="hidden" value="CustomerDownload.xlsx"/>
        <!-- 下载潜在客户导入模板 -->
        <input name="clientFileName" type="hidden" value="客户信息导入模板.xlsx"/>
        <!-- 下载潜在客户导入模板 -->
    </form>
    <form id="custUploadForm" method="post" enctype="multipart/form-data"
          action="${absoluteContextPath}/upload/ajax" style="display: none">
        <input type="file" name="file"/>
        <input type="text" name="fileType" value="xlsx">
    </form>
    <div class="modal fade" id="errorMessage" tabindex="-1" role="dialog" aria-labelledby="cardCode04"
         aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title">导入提示</h4>
                </div>
                <div class="modal-body">
                    <div id="info"></div>
                </div>
                <!-- /.modal-content -->
            </div>
            <!-- /.modal-dialog -->
        </div>
    </div>

</div>
</body>
</html>
